from itsdangerous import TimedJSONWebSignatureSerializer as Serializer,SignatureExpired,BadSignature
# from mall import settings
from django.conf import settings
def generic_verify_url(user_id,email):

    #url中含有用户信息

    #1.创建序列化器
    serializer = Serializer(settings.SECRET_KEY,3600)
    #组织数据
    data ={
        'id':user_id,
        'email':email
    }
    #3.加密处理
    token = serializer.dumps(data)

    return 'http://www.meiduo.site:8080/success_verify_email.html?token='+ token.decode()

#解密
def check_active_token(token):

    #1.创建序列化器
    serializer = Serializer(settings.SECRET_KEY, 3600)

    #2.通过loads方法对token进行解密,可能会报异常
    try:
        result = serializer.loads(token)
    except BadSignature:
        return None
    else:
        #3.返回id
        return result.get('id')

